<!--
 * @Descripttion:
 * @version:
 * @Author: cxguo
 * @Date: 2020-03-10 20:49:27
 * @LastEditors: cxguo
 * @LastEditTime: 2020-07-08 15:25:05
 -->
<template>
  <el-select
    v-model="insideVal"
    clearable
  >
    <el-option
      v-for="item in optionsData"
      :key="item.value"
      :label="item.label"
      :value="item.value"
    />
  </el-select>
</template>

<script>
import { getPayOptions, getReceOptions } from '@/api/finance/capital-cat.js'
import store from '@/store'

export default {
  components: {},
  props: {
    value: {
      type: String,
      default: null
    },
    direction: {
      type: String,
      default: '1'
    }
  },
  data() {
    return {
      optionsData: [],
      appData: store.getters.appData,
      insideVal: null
    }
  },
  computed: {
  },
  watch: {
  },
  created() {
    this.insideVal = this.value
    this.getListData()
  },
  mounted() {
  },
  methods: {
    getListData(keywords = '') {
      const method = this.direction === '0' ? getPayOptions : getReceOptions
      method().then(res => {
        if (res.data.flag) {
          const data = res.data.data
          this.optionsData = data
          this.handleCurrentData(data)
        }
      }).catch(err => {
        console.log(err)
      })
    },
    handleCurrentData(optionsData = []) {
      if (optionsData.length === 0) return
      let o = optionsData.filter(item => { return item.isDefault === '1' })
      if (o.length === 0) {
        o = optionsData[0]
      }
      this.insideVal = o.value
      this.$emit('input', o.value)
    }
  }
}
</script>

<style scoped>

</style>
